/*
 *  ====================================================================
 *  $Id: StageFactory.java 2 2004-04-23 19:41:43Z mrdon $
 *
 *  This software has been developed for the Fleet Numerical Meteorology and
 *  Oceanography Center (FNMOC), Monterey, CA.
 */
package org.twdata.pipeline;

import org.apache.commons.pool.BaseKeyedPoolableObjectFactory;

import org.springframework.beans.factory.*;

/**  Creates pipeline stages for the instance pool */
public class StageFactory extends BaseKeyedPoolableObjectFactory implements BeanFactoryAware {

  private BeanFactory factory;


  /**
   *  Makes the stage by retrieving it from the beanfactory
   *
   *@param  key  The key 
   *@return      The object
   */
  public Object makeObject(Object key) {
    return factory.getBean((String) key);
  }


  /**
   *  Recycles the stage when it is returned to the pool
   *
   *@param  key  The key
   *@param  obj  The object
   */
  public void passivateObject(Object key, Object obj) {
    ((Stage) obj).recycle();
  }


  /**
   *  Sets the beanFactory 
   *
   *@param  factory  The new beanFactory value
   */
  public void setBeanFactory(BeanFactory factory) {
    this.factory = factory;
  }
}

